

<template>
  <!-- 团购列表 -->
  <view class="Mall4j abulk-list-wrapper">
    <view class="abulk-list">
      <!-- 商品项 -->
      <block v-for="(item, index) in aBulkList" :key="index">
        <view class="abulk-list-item" :data-groupactivityid="item.groupActivityId" :data-prodid="item.prodId" @tap="toAbulkListPage">
          <!-- 商品图片 -->
          <view class="prod-img">
            <image v-if="item.prodPic" :src="item.prodPic" />
            <image v-else src="https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/icon/def.png" mode="aspectFit" />
          </view>
          <!-- 商品信息 -->
          <view class="prod-msg">
            <view class="prod-title">
              <view class="prod-describe">{{ item.groupNumber }}{{ i18n.join }}</view>{{ item.prodName }}
            </view>
            <view class="prod-price">
              <!-- 团购价 -->
              <view class="pic">
                <text class="symbol">￥</text>
                <text class="big-num">{{ wxs.parsePrice(item.actPrice)[0] }}</text>
                <text class="small-num">.{{ wxs.parsePrice(item.actPrice)[1] }}</text>
              </view>
              <!-- 原价 -->
              <view class="original-price">￥{{ wxs.toPrice(item.price) }}</view>
              <!-- <view class="cart">
              <image src="../../images/tabbar/basket-sel.png"></image>
            </view> -->
            </view>
          </view>
        </view>
      </block>
    </view>
    <view v-if="aBulkList.length > 10 && loadAll" class="loadall">{{ i18n.endTips }}</view>
    <!-- 空 -->
    <empty v-if="aBulkList.length==0" />

  </view>
</template>

<script module="wxs" lang="wxs" src="../../../wxs/number.wxs"></script>

<script>
// pages/bulk-list/bulk-list.js
var http = require("../../../utils/http.js");
import empty from "@/components/empty-tips/index.vue";

export default {
  data () {
    return {
      aBulkList: [],
      //商品列表
      current: 1,
      size: 10,
      pages: "",
      loadAll: false, // 已加载全部
    };
  },

  components: {
    empty
  },

  computed: {
    i18n () {
      return this.$t('index')
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getAbulkList();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () { },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    //头部导航标题
    uni.setNavigationBarTitle({
      title: this.i18n.groupBuyingList
    });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () { },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () { },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () { },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.current < this.pages) {
      this.setData({
        current: this.current + 1
      });
      this.getAbulkList();
    } else {
      this.setData({
        loadAll: true
      })
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () { },
  methods: {
    /**
     * 获取团购商品列表
     */
    getAbulkList: function () {
      var params = {
        url: "/groupProd/page",
        method: "GET",
        data: {
          current: this.current,
          size: this.size
        },
        callBack: res => {
          var aBulkList = [];
          if (res.current == 1) {
            aBulkList = res.records;
          } else {
            aBulkList = this.aBulkList.concat(res.records);
          }
          this.setData({
            aBulkList: aBulkList,
            pages: res.pages,
            current: res.current
          });
          console.log(this.aBulkList);
        }
      };
      http.request(params);
    },

    /**
     * 跳转到拼团商品详情
     */
    toAbulkListPage: function (e) {
      var prodId = e.currentTarget.dataset.prodid;
      var groupActivityId = e.currentTarget.dataset.groupactivityid;
      this.$Router.push({ path: '/pages/prod/prod', query: { prodid: prodId, groupActivityId: groupActivityId } })
    }
  }
};
</script>
<style>
@import "./bulk-list.css";
</style>
